//Page Object
import regeneratorRuntimer from '../../lib/runtime/runtime'
import { request } from '../../request/index.js'
import { showToast } from "../../utils/asyncWx.js"
const config = require("../../utils/config.js")
const md5 = require('../../utils/md5.js');
Page({
    data: {
        swiperList: [
            { url: '../../icons/Administrator_page/swiper_one.jpg' },
            { url: '../../icons/Administrator_page/swiper_one.jpg' },
            { url: '../../icons/Administrator_page/swiper_one.jpg' }
        ],
        //弹窗框
        showDialog: true,
        indicatorDots: true,
        autoplay: true,
        interval: 500,
        duration: 1000,
        userInfo: {},
        // 存放普通用户信息
        ShipAboutVO: {

        },
        // 储存图片链接
        shipImgPOS: [

        ],
        // 儲存船的其他信息
        ShipDetailedPO: {

        },
        // 轮播图
        Img: []

    },

    // openid用于微信用户登录
    openid: "",
    userkey: {
        loginmsg: "",
        credential: "",
        logintype: ""
    },
    userEnInfoVo: {
        encryptedData: "",
        iv: "",
        thirdSessionkey: ""
    },
    mobileEnInfoVo: {
        encryptedData: "",
        iv: "",
        thirdSessionkey: ""
    },



    // 存放图片链接
    Pic: [],

    shipAbout: {
        id: 1
    },
    sortFieldNme: 'id',
    order: true,
    //船舶的id
    id: '',
    //触发页面初始加载
    onLoad(e) {
        this.id = e.id
            // 检测是否不是登录
        if (wx.getStorageSync('openid')) {
            this.getData()
            this.getImg()
        } else {
            // 没有授权登录
            wx.redirectTo({ url: '/pages/authorization/index?id=' + this.id });
        }
    },
    // 登录跳转
    login() {
        wx.navigateTo({ url: '/pages/login_page/index?id=' + this.id });

    },
    // 获取普通用户基本的信息
    async getData() {
        console.log(this.id)
        this.shipAbout.id = this.id
        const res = await request({ url: "/ship/getShipAboutById.controller", data: { shipaboutvo: this.shipAbout } })
        this.setData({
            ShipAboutVO: res.data.ShipAboutVO,
            shipImgPOS: res.data.shipImgPOS,
            ShipDetailedPO: res.data.ShipDetailedPO
        })
    },
    // 获取轮播图的图片
    async getImg() {
        const res = await request({ url: "/picture/getBannerList.controller", method: "POST", data: { sortFieldNme: this.sortFieldNme, order: this.order } })
        console.log(res.data.resultList.length)
        for (var i = 0; i < res.data.resultList.length; i++) {
            console.log(111)
            this.Pic.push(config.BaseUrl + 'permanent/picture/' + res.data.resultList[i].picture)
        }
        console.log(this.Pic)
        this.setData({
            Img: this.Pic
        })
    },

    // 分享页面
    onShareAppMessage() {
        return {

            path: '/pages/user_page/index?id=' + this.id,
        };
    }
});